Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Use the new internal users API in the UI #150432

Merged
merged 36 commits into from
Feb 11, 2023

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Feb 7, 2023

Summary

This PR updates the UI to use the new users API introduced in #149663. I changed the backend response to accommodate the needs of the UI.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.8.0 labels Feb 7, 2023
@cnasikas cnasikas self-assigned this Feb 7, 2023
@cnasikas cnasikas requested a review from a team as a code owner February 8, 2023 16:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good, it looks like the UI is only showing the emails now though

image

Question: Does this PR switch the participants to include the currently assigned users? In the currently assigned users aren't show in the participants list.

userProfiles={userProfiles}
/>
{userActionsData?.participants ? (
{caseUsers?.reporter ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we show the Unknown user if we don't have the reporter instead of hiding the list?

I suppose another option would be to fallback to the case data right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will fallback to the case data.

@@ -957,3 +958,85 @@ export const getPersistableStateAttachment = (
...viewObject,
}),
});

export const getCaseUsersMockResponse = (): CaseUsers => {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a mock response that only has the profileUid?

...users.assignees,
...users.participants,
users.reporter,
...users.unassignedUsers,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have uniq users array like it was before in
const uidsToRetrieve = uniq([...userActionProfileUids, ...assignees]);?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Map below guarantees that only unique profiles will be added. The map will contain all valid user profiles.

},
},
],
unassignedUsers: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a stupid question 😄
What is the difference between unassignedUsers and Participants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no stupid questions 🙂! Participants are all users that did an action in the case. For example, edit a description, a comment, etc. Now, if you assign a user to a case a user action will be created containing the uid of the user. Same if you remove an assignee (unassigned user). We need the profile information for that users.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, got it. Thanks 🙂

@@ -80,137 +74,4 @@ describe('UseFindCaseUserActions', () => {
expect(spy).toHaveBeenCalledWith(basicCase.id, expect.any(AbortSignal));
expect(addError).toHaveBeenCalled();
});

describe('getProfileUids', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay!! 🎉 🙌

@js-jankisalvi
Copy link
Contributor

Code changes look good, it looks like the UI is only showing the emails now though

I also see the same behaviour. Showing username instead of email will look cleaner

@cnasikas
Copy link
Member Author

cnasikas commented Feb 9, 2023

Code changes look good, it looks like the UI is only showing the emails now though

I also see the same behaviour. Showing username instead of email will look cleaner

Damn, Rigid Rodent did it again. Thanks, both of you for finding the bug. I should be more careful. I pushed the fix and added many unit tests to check user profile variations. The bug occurred because I converted the response to camel case when the UI expected it to be in snake case. That was the format returned by the bulkGet of the security plugin. I slightly modified the backend response to be more inline with the response from the security plugin to avoid in the future these kind of bugs. Could you please also test that the avatar is displayed correctly if you change it to be an image or a different color? You can do that by going to:

Screenshot 2023-02-09 at 2 29 03 PM

Question: Does this PR switch the participants to include the currently assigned users? In the currently assigned users aren't show in the participants list.

No, but it should. I fixed it in this PR.

@js-jankisalvi
Copy link
Contributor

Damn, Rigid Rodent did it again. Thanks, both of you for finding the bug. I should be more careful. I pushed the fix and added many unit tests to check user profile variations. The bug occurred because I converted the response to camel case when the UI expected it to be in snake case. That was the format returned by the bulkGet of the security plugin. I slightly modified the backend response to be more inline with the response from the security plugin to avoid in the future these kind of bugs. Could you please also test that the avatar is displayed correctly if you change it to be an image or a different color? You can do that by going to:

Updated user profile with image, Avatar icon is displayed:
Screenshot 2023-02-09 at 14 25 58

Tested again. Looks good now. (Note: Reporter shows old profile image of elastic user)
image

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally, looks great 👍 🎉

}),
rt.partial({ uid: rt.string }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way we can tie this implementation with the security plugin 🤔 My concern is that if they make a breaking change to the response structure and make the changes throughout the code base, this won't show up as needing to be changed and it will break the UI.

Here's an idea, how about we add an integration test that does a bulk get using the security API and then does a decode using this schema? Or something like that, that way if there's a breaking change at least we'll get a failing test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing idea! I was thinking about the same but I could not find a good way to do it.

{caseUsers?.participants ? (
<UserList
dataTestSubj="case-view-user-list-participants"
theCase={caseData}
headline={i18n.PARTICIPANTS}
loading={isLoadingUserActions}
users={caseUsers.participants}
users={[...caseUsers.participants, ...caseUsers.assignees]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the ternary operator on line 245 need to be updated to reflect the assignees too?

How about we combine the array above this component and just check to see if it's not empty? Although is it even possible to have assignees but not a participant 🤔 that'd mean we don't have the reporter's information I suppose. Either probably best to check just in case the backend has a bug.

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@cnasikas cnasikas enabled auto-merge (squash) February 11, 2023 09:00
@cnasikas cnasikas merged commit 4f95b7c into elastic:main Feb 11, 2023
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cases 595 596 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cases 394.1KB 394.2KB +82.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cases 130.0KB 130.1KB +79.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @cnasikas

@cnasikas cnasikas deleted the use_users_api_ui branch February 11, 2023 10:10
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants